#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import re
import urllib2

results = []
weibo = urllib2.urlopen("http://t.qq.com/huajie_mobile/mine")
html = weibo.read()
weibo.close()

titles = re.findall('<div class="msgCnt">(.*?)<\/div>',html,re.I)

for title in titles:
    results.append("{\"title\":\"" + title + "\",\"category\":\"" + title + "\",")

images = re.findall("(http://t[\d].qpic.cn/mblogpic/.*?/)460",html,re.I)
index = 0;
for image in images:
    results[index] = results[index] + "\"origin\":\"" + image + "2000\"" + ",\"thumbnail\":\"" + image + "160\",\"tag\":\"\"},"
    index = index + 1

file = open('result.txt','a+')
for result in results:
    file.write(result + "\n")
file.close()

print len(results)

#imageRex = "http://t2\.qpic\.cn/mblogpic/*/460"
#result = re.findall(imageRex,html,re.S)
#print result
